import defaultImg from '@/components/defaultImg/defaultImg'
export default {
  data() {
    return {
      list: [

      ],
      count: 0,
      price: 0,
      checkAll: false,
      pageIndex: 1,
      loadText: [
      	'loadmore',
      	'loading',
      	'nomore'
      ],
      loadStatus: 0,
    }
  },
  components: {defaultImg},
  onLoad(){
    this.GetInvoiceNeedList()
  },
  methods: {
    async GetInvoiceNeedList(){
      let data={
			  'pageIndex': this.pageIndex,
			  'pageSize': 10,
        'order_type': 3
      }
      try{
        const res=	await this.$api.common.GetInvoiceNeedList(data)
        res.data.list.forEach(it => {
          it.checked=false
        })
        this.totalPage=res.data.total
        this.list= this.list.concat(res.data.list)
        if (Math.ceil(this.totalPage / 10) > this.pageIndex) {
				  this.loadStatus = 0
        } else {
				  this.loadStatus = 2
        }
        console.log(res)
      }catch(e){
        //TODO handle the exception
      }

    },
    onreachBottom(){

      if (Math.ceil(this.totalPage / 10) > this.pageIndex) {
        this.loadStatus = 1
        this.pageIndex++
        this.GetInvoiceNeedList()
      } else {
        this.loadStatus = 2
      }
    },
    checkOrder(val){
      this.price=0
      this.count=0
      this.$set( this.list[val],'checked',!this.list[val].checked)
      this.list.forEach(it => {
        if(it.checked){
          this.price +=it.invoice_amount
          this.count++
          this.checkAll=true
        }else{
          this.checkAll=false
        }
      })

    },
    checkAllFun(){
      console.log(11)
      if(this.checkAll){
        this.list.forEach((it,val) => {
          this.$set( this.list[val],'checked',false)
          this.price=0
          this.count=0
          // it.checked=false
        })
        this.list=this.list
      }else{
        this.list.forEach((it,val) => {
          this.$set( this.list[val],'checked',true)
				  // it.checked=true
        })
        this.list=this.list
      }
      this.checkAll=!this.checkAll
      this.list.forEach(it => {
			  if(it.checked){
			    this.price +=it.invoice_amount
			    this.count++
			  }
      })
    },
    goDetail(){
      // console.log(111)
      let arr=[]
      this.list.forEach(it => {
			  if(it.checked){
			    arr.push(it)
			  }
      })
      let data=JSON.stringify(arr)
      if(arr.length>0){
        uni.navigateTo({
				  url: '/pages_order/orderInvoice/orderInvoiveNewList?data='+ data
        })
      }else{
        uni.showToast({
          title: '请先选择一个订单',
          icon: 'none'
        })
      }

    }
  }
}
